package com.foxzzz.binary.search;

public class Solution167 {
    public int[] twoSum(int[] numbers, int target) {
        int low = 0;
        int high = numbers.length;
        while (low <= high) {
            int mid = (low + high) / 2;
           if (numbers[mid] * 2 == target) {
                high = mid;
                break;
            } else if (numbers[mid] * 2 < target) {
                low = mid + 1;
            } else if (numbers[mid] * 2 > target) {
                high = mid - 1;
            }
        }

        for (int i = high ; i >= 0; i--) {
            for (int i1 = high; i1 < numbers.length; i1++) {
                if (numbers[i] + numbers[i1] == target&&i1!=i)
                    return new int[]{i + 1, i1 + 1};
            }
        }
        return null;
    }

    public static void main(String[] args) {
        int[] sum = new Solution167().twoSum(new int[]{2, 7, 11, 15}, 9);
         int[] sum1 = new Solution167().twoSum(new int[]{2, 3, 4}, 6);
        int[] sum2 = new Solution167().twoSum(new int[]{5, 25, 75}, 100);
        int[] sum3 = new Solution167().twoSum(new int[]{-1, 0}, -1);
    }
}
